import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class PurchasePanel extends JPanel
{
	private final int WIDTH = 400;
	private final int HEIGHT = 425;
	
	private JLabel headingLabel;
	private PropertyCardPanel pcp;
	private JButton yesButton, noButton;
	private int returnValue; // 0 - no, 1 - yes

	public PurchasePanel(String name, int price)
	{
		setPreferredSize(new Dimension(WIDTH, HEIGHT));
		setBackground(new Color(200,222,186));
		returnValue = -1; // used to force user to choose yes or no
		
		headingLabel = new JLabel("Do you want to purchase this property?");
		
		add(headingLabel);
		pcp = new PropertyCardPanel();
		pcp.changeImage(name + ".jpg");
		pcp.setCostLabel(price);
		
		yesButton = new JButton("Yes");
		noButton = new JButton("No");
		
		yesButton.addActionListener(new ButtonListener());
		noButton.addActionListener(new ButtonListener());
		add(yesButton);
		add(noButton);
		add(pcp);
	}
	
	private class ButtonListener implements ActionListener
	{
		public void actionPerformed(ActionEvent event)
		{
			Object source = event.getSource();
			if(source == yesButton)
				returnValue = 1;
			else if(source == noButton)
				returnValue = 0;
		}
	}
	
	
	public int getReturnValue()
	{
		return returnValue;
	}
	
	public void resetReturnValue()
	{
		returnValue = -1;
	}
	

}
